﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Foundation.Converters
{
    public class IncrementConverter : IValueConverter
    {
        public double Increment { get; set; }

        public IncrementConverter()
        {
            Increment = 1.0;
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;
            var val = double.Parse(value.ToString());
            val += Increment;
            return val;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;
            double val;
            if (double.TryParse(value.ToString(), out val))
            {
                val -= Increment;
                return val;
            }

            return null;
        }
    }
}
